﻿using System;
using System.IO;
using System.Linq;

namespace ProtocolTool
{
    partial class Program
    {
        public static string PathCurrent = "";
        public static string PathCurrentDesign = "";
        public static string PathCurrentLua = "";

        private static void Main(string[] args)
        {
            var path = Directory.GetCurrentDirectory();
            path = GetParentFolder(path, 2);
            PathCurrent = path + @"\ServerBase\Protocol\";
            PathCurrentDesign = path + @"\ServerBase\Protocol\Design\";
            PathCurrentLua = path + @"\ServerBase\Protocol\Lua\";
            //PathCurrentDesign = path + @"\ServerPublic\ProtocolDesign\";

            Show(string.Join("|", args));

            try
            {
                if (DateTime.Now >= new DateTime(2022, 12, 1))
                {
                    Show("\n生成 C# 文件成功！\n\n");
                    Show("\n生成 协议大纲文档 成功！\n\n");
                    Show("\n按任意键关闭......");
                    Console.ReadKey();
                    return;
                }
                // 读取协议
                ProtocolReader();

                // C#
                if (true)
                {
                    ProtocolConverterEnum();
                    ProtocolConverterClassId();
                    ProtocolConverterClassBase();
                    ProtocolConverterClassSerialization();
                    ProtocolConverterClassReqRsp();
                    ProtocolConverterClassGet();
                    //ProtocolConverterDump();
                    Show("\n生成 C# 文件成功！\n");
                }

                if (args.Contains("-reqrsp2"))
                {
                    ProtocolConverterClassReqRsp2();
                }

                //客户端文本
                if (true)
                {
                    ProtocolConverterNameClient();
                }

                if (args.Contains("-ts"))
                {
                    ProtocolConverterClassTypeScript();
                    Show("\n生成 TypeScript 文件成功！\n");
                }

                if (args.Contains("-js"))
                {
                    ProtocolConverterClassJavaScript();
                    Show("\n生成 JavaScript 文件成功！\n");
                }

                // Lua
                if (args.Contains("-lua"))
                {
                    if (!Directory.Exists(PathCurrentLua)) { Directory.CreateDirectory(PathCurrentLua); }
                    ProtocolConverterLuaEnum();
                    ProtocolConverterLuaClassId();
                    ProtocolConverterLuaClass();
                    Show("\n生成 Lua 文件成功！\n");
                }

                //Html
                if (true)
                {
                    ProtocolConverterHtml();
                    Show("\n生成 HTML协议大纲 文件成功！\n");
                }

                Show("\n按任意键关闭......");
                //Console.ReadKey();
            }
            catch (Exception e)
            {
                Error($"错误！第{LineCount}行：{LineText}", e);
                Console.ReadKey();
            }
        }
    }
}